/**
 * 
 */
package com.appspot.myjsf2;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;

/**
 * @author andyz
 *
 */
public class OAuthEntryServlet extends HttpServlet{
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
		System.out.println("hello from system.out");
		//resp.setContentType("text/plain");
		//resp.getWriter().println("Hello, world");
		try {
			String authUrl = "http://myjsf2.appspot.com/oAuthCallback";
			String redirectUrl = OAuther.getAuthUrl(authUrl);
			OAuthConsumer consumer = OAuther.consumer;
			OAuthProvider provider = OAuther.provider;
			System.out.println("Request Token: " + consumer.getToken());
			System.out.println("Request Secret: " + consumer.getTokenSecret());
			resp.sendRedirect(redirectUrl);

		} catch (OAuthMessageSignerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthNotAuthorizedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthExpectationFailedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (OAuthCommunicationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
